const app = getApp()
const $api = require('../../utils/api.js').API;
var WxParse = require('../../wxParse/wxParse.js');
Page({
    data: {
        id:0,
        info:{},
        imgUrl:app.globalData.imgUrl,
        cartShow:false,
        cartNUm:1
    },
    onLoad: function(e) {
        var id = e.id;
        this.setData({
            id:e.id
        })
        this.getInfo(e.id)
    },
    getInfo:function(id){
        var that = this
        var data = {'id':id}
        $api.get('score/info',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                var article = res.data.data.content;
                WxParse.wxParse('article', 'html', article,that, 5,that.data.imgUrl);
                that.setData({
                    info:res.data.data
                })
            }
        }).catch(err => {
            //请求失败
            //console.log('job','请求失败');
        })
    },
    cartAdd:function(){
        var that = this
        var data = {
            'goods_id':this.data.id,
            'uid':wx.getStorageSync('uid'),
            'num':this.data.cartNUm
        }
        $api.post('cart/add',data).then(res => {
            //请求成功
            wx.showToast({
                title:res.data.msg,
                duration:3000,
                mask:true, 
                icon:'none',
            })
            that.setData({
                cartShow:false
            })
        }).catch(err => {
            //请求失败
            //console.log('job','请求失败');
        })
    },
    cart:function(){
        this.setData({
            cartShow:true
        })
    },
    plus:function(){
        this.setData({
            cartNUm:this.data.cartNUm+1
        })
    },
    less:function(){
        if(this.data.cartNUm > 1){
            this.setData({
                cartNUm:this.data.cartNUm-1
            })
        }
    },
    order:function(){
        var str = this.data.id
        var num = this.data.cartNUm
        wx.navigateTo({
            url:'/pages/pointsMall/order?str='+str+'&num='+ num
        })
    },
    gocart:function(){
        wx.navigateTo({
            url:'/pages/pointsMall/cart/index'
        })
    },
    onShareAppMessage: function() {
        return {
            title: this.data.info.name+"-天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
    }
});